Public Class Frm_login
  Private L As Integer, T As Integer, X As Integer, Y As Integer

  Public Sub New()
    InitializeComponent()

  End Sub

  Private Sub Frm_login_Load(sender As Object, e As EventArgs) Handles Me.Load

  End Sub

  ''' <summary>
  ''' 登录相关代码
  ''' </summary>
  ''' <param name="sender"></param>
  ''' <param name="e"></param>
  Private Sub Bt_login_Click(sender As Object, e As EventArgs) Handles Bt_login.Click
    Login()
  End Sub

#Region "鼠标事件"
  Private Sub Bt_loginMouse_Hover(sender As Object, e As EventArgs) Handles Bt_login.MouseHover
    Bt_login.BackColor = Color.SlateGray
  End Sub

  Private Sub Bt_loginMouse_Leave(sender As Object, e As EventArgs) Handles Bt_login.MouseLeave
    Bt_login.BackColor = Color.LightSlateGray
  End Sub

  Private Sub Bt_loginMouse_Down(sender As Object, e As MouseEventArgs) Handles Bt_login.MouseDown
    Bt_login.BackColor = Color.DeepSkyBlue
  End Sub

  Private Sub Bt_cancelMouse_Hover(sender As Object, e As EventArgs) Handles Bt_cancel.MouseHover
    Bt_cancel.BackColor = Color.SlateGray
  End Sub

  Private Sub Bt_cancelMouse_Leave(sender As Object, e As EventArgs) Handles Bt_cancel.MouseLeave
    Bt_cancel.BackColor = Color.LightSlateGray
  End Sub

  Private Sub Bt_cancelMouse_Down(sender As Object, e As MouseEventArgs) Handles Bt_cancel.MouseDown
    Bt_cancel.BackColor = Color.DeepSkyBlue
  End Sub


#End Region

#Region "程序控制"

  Private Sub Bt_cancel_Click(sender As Object, e As EventArgs) Handles Bt_cancel.Click
    End
  End Sub


  Private Sub Frm_login_Shown(sender As Object, e As EventArgs) Handles Me.Shown
    ''*****获取状态**********
    Txt_username.Text = My.Settings.username.ToString
    Txt_userpass.Text = My.Settings.userpass.ToString
    '************************************************
    If My.Settings.save_userinfo = True Then
      Cb_saveinfo.CheckState = CheckState.Checked
    Else
      Cb_saveinfo.CheckState = CheckState.Unchecked
    End If
    '***********************************************
    If My.Settings.login_stats = True Then
      Cb_autologin.CheckState = CheckState.Checked
    Else
      Cb_autologin.CheckState = CheckState.Unchecked
    End If
    ''********自动登录控制**************************
    If Cb_autologin.CheckState = CheckState.Checked Then
      Login()
    End If
  End Sub

  Private Sub Cb_saveinfo_CheckedChanged(sender As Object, e As EventArgs) Handles Cb_saveinfo.CheckedChanged
    If Txt_username.Text = "" Or Txt_userpass.Text = "" Then
      If Cb_saveinfo.CheckState = CheckState.Checked Then MsgBox("请输入用户名或密码为空!", MsgBoxStyle.Exclamation, "警告")
      Cb_saveinfo.CheckState = CheckState.Unchecked
    End If
    ''*************************************************
    If Cb_saveinfo.CheckState = CheckState.Checked Then
      My.Settings.save_userinfo = True
      My.Settings.username = Txt_username.Text.ToString
      My.Settings.userpass = Txt_userpass.Text.ToString
      My.Settings.Save()
    ElseIf Cb_saveinfo.CheckState = CheckState.Unchecked Then
      My.Settings.save_userinfo = False
      My.Settings.username = ""
      My.Settings.userpass = ""
      My.Settings.Save()
    End If
  End Sub

  Private Sub Cb_autologin_CheckedChanged(sender As Object, e As EventArgs) Handles Cb_autologin.CheckedChanged
    If Txt_username.Text = "" Or Txt_userpass.Text = "" Then
      If Cb_autologin.CheckState = CheckState.Checked Then MsgBox("请输入用户名或密码为空!", MsgBoxStyle.Exclamation, "警告")
      Cb_autologin.CheckState = CheckState.Unchecked
    End If
    ''**************************************************
    If Cb_autologin.CheckState = CheckState.Checked Then
      Cb_saveinfo.CheckState = CheckState.Checked
      ''-----------------------------------------
      My.Settings.login_stats = True
      My.Settings.Save()
    ElseIf Cb_autologin.CheckState = CheckState.Unchecked Then
      My.Settings.login_stats = False
      My.Settings.Save()
    End If
  End Sub

#Region "文本框焦点"
  Private Sub Panel3_Click(sender As Object, e As EventArgs) Handles Panel3.Click
    Txt_username.Select()
  End Sub
  Private Sub Panel4_Click(sender As Object, e As EventArgs) Handles Panel4.Click
    Txt_userpass.Select()
  End Sub

  Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
    Txt_username.Select()
  End Sub

  Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
    Txt_userpass.Select()
  End Sub


#End Region

#Region "窗体控制"
  Private Sub Panel1_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel1.MouseDown
    Down_frm(e)
  End Sub

  Private Sub Panel1_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel1.MouseMove
    Move_frm(Panel1, e)
  End Sub

  Private Sub Label2_MouseDown(sender As Object, e As MouseEventArgs) Handles Label2.MouseDown
    Down_frm(e)
  End Sub
  Private Sub Label3_MouseDown(sender As Object, e As MouseEventArgs) Handles Label3.MouseDown
    Down_frm(e)
  End Sub
  Private Sub Label4_MouseDown(sender As Object, e As MouseEventArgs) Handles Label4.MouseDown
    Down_frm(e)
  End Sub

  Private Sub Label2_MouseMove(sender As Object, e As MouseEventArgs) Handles Label2.MouseMove
    Move_frm(Label2, e)
  End Sub

  Private Sub Label3_MouseMove(sender As Object, e As MouseEventArgs) Handles Label3.MouseMove
    Move_frm(Label3, e)
  End Sub

  Private Sub Label4_MouseMove(sender As Object, e As MouseEventArgs) Handles Label4.MouseMove
    Move_frm(Label4, e)
  End Sub

  ''' <summary>
  ''' 窗体移动
  ''' </summary>
  ''' <param name="OBJ"></param>
  ''' <param name="E"></param>
  Sub Move_frm(ByVal OBJ As Object, ByVal E As Object)
    If OBJ.Capture = True Then
      Top = E.Y + T - Y
      Left = E.X + L - X
      L = Left
      T = Top
    End If
  End Sub

  ''' <summary>
  ''' 窗体点击事件
  ''' </summary>
  ''' <param name="e"></param>
  Sub Down_frm(ByVal e As Object)
    L = Left
    T = Top
    X = e.X
    Y = e.Y
  End Sub


#End Region


#End Region

#Region "相关函数过程"

  Sub Login()
    If Txt_userpass.Text = "666" And Txt_username.Text = "admin" Then
      Frm_Main.Show()
      Visible = False
    Else
      MsgBox("密码或用户名有误!", MsgBoxStyle.Critical, "登陆失败")
    End If
  End Sub


#End Region
End Class
